package com.csun.cmny.provider.device.csun.camera;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import io.netty.handler.timeout.IdleStateHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-12-27 08:58
 * @Description:
 */
@Component
public class CameraNettyTcpChannelHandler extends ChannelInitializer<SocketChannel> {

    @Resource
    private CameraNettyTcpServerHandler cameraNettyTcpServerHandler;

    public void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast(new IdleStateHandler(60, 70, 80, TimeUnit.SECONDS));
        socketChannel.pipeline().addLast(new ObjectEncoder());
//        socketChannel.pipeline().addLast("framedecoder",new LengthFieldBasedFrameDecoder(1024 * 1024 *1024, 0, 4,0,4));
        socketChannel.pipeline().addLast(cameraNettyTcpServerHandler);
    }

}
